package com.lanou.myapp.comic.recommendedcomic.contentrecommendedcomic;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.ImageView;
import android.widget.ListView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.gson.Gson;
import com.lanou.myapp.R;
import com.lanou.myapp.imageloader.GsonRequest;
import com.lanou.myapp.imageloader.VolleySingleton;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/1/18.
 */
public class ContentRecommendedcomicActivity extends AppCompatActivity {
    private ImageView imageView;
    private ListView listView;
    private RequestQueue queue;
    private ContentRecommendedComicAdapter adapter;
    private List<Picture> datas;
    private Context context;
    private String url;
    private NetworkImageView networkImageView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_content_recommended_comic);

        listView = (ListView) findViewById(R.id.listView_content_recommended_comic);
        Intent intent = getIntent();
        String a = intent.getStringExtra("Id");
        String p = "http://api.alithefox.net/comics/";
        url = p + a;
//        Log.d("aaaaa",c);

//        queue = Volley.newRequestQueue(this);
        adapter = new ContentRecommendedComicAdapter(ContentRecommendedcomicActivity.this);


        GsonRequest<DataBeans> request = new GsonRequest<DataBeans>(url, DataBeans.class, new Response.Listener<DataBeans>() {
            @Override
            public void onResponse(DataBeans response) {
                adapter.addData(response.getData().getImages());
                listView.setAdapter(adapter);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        VolleySingleton.getInstance()._addRequest(request);

//        StringRequest request = new StringRequest(c, new Response.Listener<String>() {
//            @Override
//            public void onResponse(String response) {
////                Log.d("ddddd",response);
//                Gson gson = new Gson();
//                datas = new ArrayList<>();
//                DataBeans beans = gson.fromJson(response, DataBeans.class);
//                Data data = beans.getData();
//                datas = data.getImages();
//                adapter.addData(datas);
//                listView.setAdapter(adapter);
//            }
//        }, new Response.ErrorListener() {
//            @Override
//            public void onErrorResponse(VolleyError error) {
//                error.printStackTrace();
//            }
//        });
//
//        queue.add(request);
//
//    }

    }
}